package com.ouc.openplatform.zykt.orderManage.service.impl;

import java.util.List;

import com.github.abel533.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ouc.openplatform.pojo.EUDataGridResult;
import com.ouc.openplatform.zykt.orderManage.dao.DD_OrderDao;
import com.ouc.openplatform.zykt.orderManage.model.DD_Order;
import com.ouc.openplatform.zykt.orderManage.service.DD_OrderService;

public class DD_OrderServiceImpl implements DD_OrderService{

	private DD_OrderDao orderDao;

	public DD_OrderDao getOrderDao() {
		return orderDao;
	}

	public void setOrderDao(DD_OrderDao orderDao) {
		this.orderDao = orderDao;
	}

	@Override
	public EUDataGridResult findAllOrder(String orderNo,String productDescription, String productLine,String checkState,int page,int rows) {
		//分页处理
		PageHelper.startPage(page, rows);
		List<DD_Order> orderList = orderDao.findAllOrder(orderNo, productDescription, productLine,checkState);
		//计算应抽数量
		for (DD_Order dd_Order : orderList) {
			if(dd_Order.getPlanCount()==1){
				dd_Order.setCheckCount(1);
			}else if(dd_Order.getPlanCount()<=50){
				dd_Order.setCheckCount(2);
			}else{
				dd_Order.setCheckCount(3);
			}
		}
		//创建一个返回值对象
		EUDataGridResult result = new EUDataGridResult();
		result.setRows(orderList);
		//取记录总条数
		PageInfo<DD_Order> pageInfo = new PageInfo<DD_Order>(orderList);
		result.setTotal(pageInfo.getTotal());
		return result;
	}

	//2.根据订单编号修改订单状态-----sxl
	@Override
	public int updateOrderStateByOrderNo(String orderNo, int status) {
		 DD_Order record=new DD_Order();
		 record.setCheckState(status);
		 Example example = new Example(DD_Order.class);
		 example.createCriteria().andLike("orderNo", orderNo);
		 return orderDao.updateByExampleSelective(record, example);
	}

	
	
	
}
